<script setup>
import {
  onMounted,
  reactive,
  ref,
  getCurrentInstance,
  computed,
  nextTick,
} from "vue";
import { onLoad, onReachBottom, onShow } from "@dcloudio/uni-app";
import { handleGoBack } from "@/utils/router";
import { chartBusiness, version } from "@/services/index";
import { appScTransferCountUnsigned } from "@/services/transfer";
import { isOpens } from "@/utils/directive.js";
import { messageCount, damageUnApproveCount } from "@/services/user";
import { purchaseCount, purchaseLogistics } from "@/services/send";
import { useUserStore } from "@/stores/user";
import useFormat from "@/hooks/format";
import {
  setStorageSyncWithExpire,
  getStorageSyncWithExpire,
  removeStorageSyncWithExpire,
} from "@/utils/care";

// 首页图片资源
import logoindex from "@/static/index/logoindex.png";
import logoindex2 from "@/static/index/logoindex2.png";
import msgess from "@/static/index/msgess.png";

const statusBarHeight = ref(0);
const menuButtonInfo = ref(null);
const loading = ref(true);
const userInfo = ref({});
const shopType = ref(1);
const isShopQ = ref(false);

const showSelect = ref("");
const PurchaseLogisticsCount = ref(0);
const SystemVersion = ref("");
const Version = ref({});

onLoad(() => {});

onShow(() => {
  uni.getNetworkType({
    success: function (res) {
      if (res.networkType == "none") {
        showWord.value = true;
      } else {
      }
    },
  });
  if (uni.getStorageSync("more")) {
    isShopQ.value = true;
  } else {
    isShopQ.value = false;
  }
  if (uni.getStorageSync("user")) {
    userInfo.value = uni.getStorageSync("user")
      ? JSON.parse(uni.getStorageSync("user"))
      : {};
    console.log(JSON.parse(uni.getStorageSync("user")));
  } else {
    uni.reLaunch({
      url: "/pages/login/login",
    });
  }
  shopType.value = uni.getStorageSync("shopType")
    ? uni.getStorageSync("shopType")
    : 1;
  if (uni.getStorageSync("selectShopType")) {
    showSelect.value = uni.getStorageSync("selectShopType");
    if (isOpens(["shop:chart:business"])) {
      getChartBusiness();
    }
  } else {
    showSelect.value = "";
    uni.removeStorageSync("user");
    uni.removeStorageSync("X-Auth-Token");
    uni.reLaunch({
      url: "/pages/login/login",
    });
  }
  if (isOpens(["manager:scTransfer:countUnsigned"])) {
    getappScTransferCountUnsigned();
  }
  if (isOpens(["shop:scTransfer:countUnsigned"])) {
    getappScTransferCountUnsigned();
  }
  if (
    isOpens(["shop:stock:adjust:damage:query"]) ||
    isOpens(["manager:stock:adjust:damage:query"])
  ) {
    getDamageUnApproveCount();
  }
  if (uni.getStorageSync("X-Auth-Token")) {
    getmessageCount();
  }
  if (
    uni.getStorageSync("X-Auth-Token") &&
    (isOpens(["manager:purchase:query"]) || isOpens(["shop:purchase:query"]))
  ) {
    getPurchaseCount();
    getPurchaseLogisticsCount();
  }
  // setTimeout(() => {
  loading.value = false;
  // }, 1000);
  // #ifdef APP-PLUS
  getVersion();
  // #endif
});

const purchaseCountObj = ref(null);
const getPurchaseCount = async () => {
  let res = await purchaseCount();

  purchaseCountObj.value = res.data.statusCounts[5] || 0;
};

const getPurchaseLogisticsCount = async () => {
  let res = await purchaseLogistics({
    pageIndex: 1,
    pageSize: 1,
    purchaseOrderDeliverStatus: 5,
  });

  PurchaseLogisticsCount.value = res.data.totalCount || 0;
};

const UnApproveCount = ref({});
const getDamageUnApproveCount = async () => {
  let res = await damageUnApproveCount();

  UnApproveCount.value = res.data;
};

const totallObj = ref({});

const getappScTransferCountUnsigned = async () => {
  let res = await appScTransferCountUnsigned({});
  totallObj.value = res.data;
};

const msgessObj = ref({});

const getmessageCount = async () => {
  let res = await messageCount({});
  msgessObj.value = res.data;
};

// 获得当前组件实例
const instance = getCurrentInstance();
//兼容小程序
// #ifdef MP-WEIXIN
menuButtonInfo.value = uni.getMenuButtonBoundingClientRect();
// #endif
statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight;
const codeData = ref({
  imgURL: "",
  showcanvas: true,
});
// init data loading
const initDataLoading = ref(true);
// api得到的数据 展示
const showDetail = ref(undefined);

// go back
const goBack = () => {
  uni.removeStorageSync("X-Auth-Token");

  uni.removeStorageSync("more");
  uni.navigateTo({
    url: "/pages/login/login",
  });
  uni.removeStorageSync("user");
};

const goTo = (url, type) => {
  if (loading.value) return;
  console.log(url);
  if (url === 1) {
    return;
  }
  if (!url) {
    uni.showToast({
      title: "暂未开放，敬请期待",
      icon: "none",
    });
    return;
  }
  uni.navigateTo({
    url,
  });
};

onMounted(() => {
  // initData();、
});

const goSelectShopType = () => {
  if (userInfo.value.adminPermission && userInfo.value.storePermission) {
    uni.navigateTo({
      url: "/pages/users/switch-word/index",
    });
  } else {
  }
};
const chartSelectIndex = ref(0);
const chartSelect = (index) => {
  console.log(index);
  chartSelectIndex.value = index;
};
//数据
const businessDet = ref({});
const chartCategoryList = ref([]);
const getChartBusiness = async () => {
  const res = await chartBusiness({
    datePick: 1,
    shopId: userInfo.value.shopId,
  });
  businessDet.value = res.data;
};

//图表
const chartData = ref({});
const opts = ref({
  color: [
    "#1890FF",
    "#91CB74",
    "#FAC858",
    "#EE6666",
    "#73C0DE",
    "#3CA272",
    "#FC8452",
    "#9A60B4",
    "#ea7ccc",
  ],
  padding: [15, 10, 0, 15],
  enableScroll: true,
  legend: {},
  xAxis: {
    disableGrid: true,
    scrollShow: true,
    itemCount: 4,
  },
  yAxis: {
    gridType: "dash",
    dashLength: 2,
  },
  extra: {
    line: {
      type: "straight",
      width: 2,
      activeType: "hollow",
    },
  },
});

const chartRes = ref({
  categories: ["2018", "2019", "2020", "2021", "2022", "2023"],
  series: [
    {
      name: "成交量A",
      data: [35, 8, 25, 37, 4, 20],
    },
    {
      name: "成交量B",
      data: [70, 40, 65, 100, 44, 680],
    },
    {
      name: "成交量C",
      data: [100, 80, 95, 150, 112, 132],
    },
  ],
});

const chartDataZ = ref({});

const optsZ = ref({
  dataLabel: false,
  dataPointShape: false,
  legend: {
    show: false,
  },
  color: [
    "#F2F3F5",
    "#91CB74",
    "#FAC858",
    "#EE6666",
    "#73C0DE",
    "#3CA272",
    "#FC8452",
    "#9A60B4",
    "#ea7ccc",
  ],
  padding: [20, 0, 20, 0],
  enableScroll: false,

  xAxis: {
    disabled: true,
    disableGrid: true,
    title: " ",
    scrollShow: true,
    axisLine: false,
  },
  yAxis: {
    disabled: true, //Y轴直接隐藏
    disableGrid: true,
    gridColor: "#CCCCCC",
    data: [
      {
        min: 0,
      },
    ],
  },
  extra: {
    column: {
      type: "group",
      width: 15,
      activeBgColor: "#000000",
      activeBgOpacity: 0.08,
      categoryGap: 0,
      seriesGap: 0,
      padding: [0, 0, 0, 0],
    },
  },
});

const chartResZ = ref({
  categories: ["1", "2", "1", "3", "4", "5", "5", "5", "5"],
  series: [
    {
      labelShow: false,
      name: "目标值",

      data: [
        {
          color: "#FFF000",
          value: 1,
        },
        10,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
      ],
    },
  ],
});

nextTick(() => {
  chartData.value = JSON.parse(JSON.stringify(chartRes.value));
  chartDataZ.value = JSON.parse(JSON.stringify(chartResZ.value));
});

const goSetting = () => {
  uni.navigateTo({
    url: "/pages/mysetting/up/index",
  });
};

const setting = () => {
  uni.openAppAuthorizeSetting({
    success(res) {
      console.log(res);
    },
  });
};

const showWord = ref(false);

const connected = () => {
  if (uni.getStorageSync("more")) {
    isShopQ.value = true;
  } else {
    isShopQ.value = false;
  }
  if (uni.getStorageSync("user")) {
    userInfo.value = uni.getStorageSync("user")
      ? JSON.parse(uni.getStorageSync("user"))
      : {};
    console.log(JSON.parse(uni.getStorageSync("user")));
  } else {
    uni.reLaunch({
      url: "/pages/login/login",
    });
  }

  shopType.value = uni.getStorageSync("shopType")
    ? uni.getStorageSync("shopType")
    : 1;
  if (uni.getStorageSync("selectShopType")) {
    showSelect.value = uni.getStorageSync("selectShopType");
    if (isOpens(["shop:chart:business"])) {
      getChartBusiness();
    }
  } else {
    showSelect.value = "";
    uni.removeStorageSync("user");
    uni.removeStorageSync("X-Auth-Token");
    uni.reLaunch({
      url: "/pages/login/login",
    });
  }

  if (isOpens(["manager:scTransfer:countUnsigned"])) {
    getappScTransferCountUnsigned();
  }
  if (isOpens(["shop:scTransfer:countUnsigned"])) {
    getappScTransferCountUnsigned();
  }

  if (
    isOpens(["shop:stock:adjust:damage:query"]) ||
    isOpens(["manager:stock:adjust:damage:query"])
  ) {
    getDamageUnApproveCount();
  }
  if (uni.getStorageSync("X-Auth-Token")) {
    getmessageCount();
  }
  if (
    uni.getStorageSync("X-Auth-Token") &&
    (isOpens(["manager:purchase:query"]) || isOpens(["shop:purchase:query"]))
  ) {
    getPurchaseCount();
    getPurchaseLogisticsCount();
  }

  // setTimeout(() => {
  loading.value = false;
  // }, 1000);
};
const reload = () => {
  uni.getNetworkType({
    success: function (res) {
      if (res.networkType == "none") {
        showWord.value = true;
      } else {
        connected();
        nextTick(() => {
          showWord.value = false;
        });
      }
    },
  });
};

// 本版更新模块

const showVersion = ref(false);
const getVersion = async () => {
  // #ifdef APP-PLUS

  if (uni.getSystemInfoSync) {
    let systemInfo = uni.getSystemInfoSync();

    SystemVersion.value = systemInfo.appWgtVersion;
  } else if (plus) {
    // 非H5平台，例如App或小程序
    // console.log('应用版本: ' + plus.runtime.version); // 应用版本
    SystemVersion.value = plus.runtime.version;
  }

  console.log("ASystemVersion", SystemVersion.value);
  let res = await version();

  Version.value = res.data;

  let isUpdate = compare(Version.value.version, SystemVersion.value);
  if (isUpdate == 1) {
    // console.log("需要更新");
    if (Version.value.isForced == 1) {
      upDate();
    } else {
      if (!getStorageSyncWithExpire("isSV")) {
        showVersion.value = true;
      }
    }
  } else if (isUpdate == 0) {
    console.log("不需要更新");
  } else if (isUpdate == -1) {
    console.log("更新过小");
  }
  // #endif
};

function compare(v1 = "0", v2 = "0") {
  v1 = String(v1).split(".");
  v2 = String(v2).split(".");
  const minVersionLens = Math.min(v1.length, v2.length);

  let result = 0;
  for (let i = 0; i < minVersionLens; i++) {
    const curV1 = Number(v1[i]);
    const curV2 = Number(v2[i]);

    if (curV1 > curV2) {
      result = 1;
      break;
    } else if (curV1 < curV2) {
      result = -1;
      break;
    }
  }
  return result;
}

const closeVersion = () => {
  showVersion.value = false;
};
const upDate = () => {
  removeStorageSyncWithExpire("isSV");
  //console.log('进入方法',data.data.appPath)
  uni.showLoading({
    title: "更新中...",
    mask: true,
  });

  uni.downloadFile({
    url: Version.value.url,
    success: function (downloadResult) {
      console.log("downloadResult", downloadResult);
      if (downloadResult.statusCode === 200) {
        plus.runtime.install(
          downloadResult.tempFilePath,
          {
            force: true,
          },
          function () {
            uni.hideLoading();
            uni.showToast({
              title: "安装成功",
              icon: 2000,
              duration: 1000,
            });
            setTimeout(function () {
              plus.runtime.restart();
            }, 1100);
          },
          function (e) {
            // })
            uni.hideLoading();
            console.log(e);
            uni.showToast({
              title: "安装失败",
              icon: 2000,
              duration: 1000,
            });
          }
        );
      }
    },
    fail: function (res) {
      console.log("失败");
    },
    error: function (res) {
      console.log(res);
    },
  });
};

const VersionQx = () => {
  showVersion.value = false;
  // 1000 * 60 * 60 * 24 * 7
  setStorageSyncWithExpire("isSV", true, 1000 * 60 * 60 * 24 * 7);
};
const VersionQr = () => {
  upDate();
};
</script>

<template>
  <view class="my-content">
    <noWork></noWork>
    <!-- <van-skeleton :loading="loading" class="title1"> -->
    <view class="title">
      <view
        class="title-status"
        :style="'height:' + statusBarHeight + 'px'"
      ></view>

      <view class="title-text">
        <image :src="logoindex" mode="heightFix" />
        <!-- <image :src="logoindex2" mode="heightFix" /> -->

        <text class="text-out" @click="goSelectShopType()"
          >{{ shopType == 1 ? "店铺端" : "运营端" }}
          <van-icon
            v-if="userInfo.adminPermission && userInfo.storePermission"
            class="icon-q"
            size="28rpx"
            name="sort"
          />
        </text>

        <view class="setting">
          <!-- <van-icon size="48rpx" name="chat-o" dot /> -->
          <view class="msgess-icon">
            <view class="box" @click="goTo('/pages/users/news/index')">
              <up-badge
                bgColor="#F53F3F"
                max="99"
                :value="msgessObj.count || 0"
              ></up-badge>
            </view>
            <image
              @click="goTo('/pages/users/news/index')"
              :src="msgess"
              mode="scaleToFill"
            />
          </view>
          <view class="msgess-icon">
            <image
              @click="goSetting()"
              src="https://cloud-erp.yibaitao.cn/static/index/setting.png"
              mode="scaleToFill"
            />
          </view>

          <!-- <up-icon name="setting" color="#2979ff" size="48rpx"></up-icon> -->
        </view>
      </view>
    </view>

    <view
      class="user-info"
      :style="'margin-top: calc(-400rpx' + ' + ' + statusBarHeight + 'px) '"
    >
      <up-skeleton
        :loading="loading"
        avatar
        rows="1"
        :title="true"
        avatarSize="100rpx"
      >
        <view class="user-info-img">
          <image src="@/static/home/arr.png" mode="apectFill" />
          <view class="user-info-text">
            <view
              v-if="showSelect == 'shop'"
              class="user-info-text-name"
              @click="goTo(isShopQ ? '/pages/users/switch/index' : 1)"
              >{{ userInfo.shopName }}
              <van-icon
                v-if="isShopQ"
                class="user-q"
                name="play"
                size="28rpx"
                color="#C9CDD4"
              />
            </view>
            <view v-if="showSelect == 'admin'" class="user-info-text-name"
              >{{ userInfo.name }}
            </view>
            <view class="user-info-text-time"
              ><text
                >{{ showSelect == "shop" ? userInfo.name : "" }}
                <text v-if="showSelect == 'shop'" class="hx-to">|</text>
                {{ "工号: " + userInfo.employeeNo }}</text
              >
              <!-- <van-icon name="sort" size="24rpx" color="#1679FB" />
              <text class="user-info-text-time-text">切换</text> -->
            </view>
          </view>
        </view>
      </up-skeleton>
    </view>

    <view v-if="showSelect == 'shop'">
      <view
        class="pay-yye"
        v-permission="['shop:chart:business']"
        @click="goTo('/pages/cashier/business/index')"
      >
        <up-skeleton :loading="loading" :title="true" titleWidth="180rpx">
          <view class="pay-yye-text">
            <text>今日营业额</text>
            <up-icon name="arrow-right" color="#86909C" size="28rpx"></up-icon>
          </view>
        </up-skeleton>

        <view class="pay-yye-k">
          <up-skeleton
            rows="1"
            :loading="loading"
            :title="true"
            class="pay-yye-k-sk"
          >
            <view class="pay-yye-item">
              <view class="pay-yye-item-title">总销售额</view>
              <view class="pay-yye-item-num pay-yye-item-num-left">
                <up-count-to
                  color="#1679fb"
                  :duration="500"
                  :startVal="0"
                  :bold="true"
                  separator=","
                  fontSize="36rpx"
                  :endVal="businessDet.salesTotalAmount || 0"
                  :decimals="2"
                ></up-count-to>
              </view>
            </view>
          </up-skeleton>

          <up-skeleton
            rows="1"
            :loading="loading"
            :title="true"
            class="pay-yye-k-sk"
          >
            <view class="pay-yye-item">
              <view class="pay-yye-item-title">总实收</view>
              <view class="pay-yye-item-num">
                <up-count-to
                  color="#1d2129"
                  :duration="500"
                  :startVal="0"
                  :bold="true"
                  separator=","
                  fontSize="36rpx"
                  :endVal="businessDet.salesTotal || 0"
                  :decimals="2"
                ></up-count-to>
              </view>
            </view>
          </up-skeleton>
          <up-skeleton
            rows="1"
            :loading="loading"
            :title="true"
            class="pay-yye-k-sk"
          >
            <view class="pay-yye-item">
              <view class="pay-yye-item-title">总订单数</view>
              <view class="pay-yye-item-num">
                <up-count-to
                  color="#1d2129"
                  :duration="500"
                  :startVal="0"
                  :bold="true"
                  separator=","
                  fontSize="36rpx"
                  :endVal="businessDet.orderCount || 0"
                ></up-count-to>
              </view>
            </view>
          </up-skeleton>
        </view>
      </view>

      <view class="contents">
        <view class="contents-title">
          <up-skeleton :loading="loading" :title="true" titleWidth="140rpx">
            <text>收银管理</text>
          </up-skeleton>
        </view>

        <view class="contents-list">
          <view
            v-permission="['shop:order:query']"
            class="contents-list-item"
            @click="goTo('/pages/cashier/sales_order/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop01.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">销售单查询</view>
            </van-skeleton>
          </view>
          <!-- /pages/cashier/shop_info/index -->
          <!-- <view class="contents-list-item" @click="goTo('')">
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop02.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">门店收支</view>
            </van-skeleton>
          </view> -->
          <view
            v-permission="['shop:order:create']"
            class="contents-list-item"
            @click="goTo('/pages/cashier/goods/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop03.png"
                mode="apectFill"
              />
            </view>

            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">手机收银</view>
            </van-skeleton>
          </view>
          <view
            v-permission="[
              'shop:chart:business',
              'shop:chart:shop',
              'shop:chart:category',
              'shop:chart:product',
              'shop:chart:payType',
            ]"
            class="contents-list-item"
            @click="goTo('/pages/cashier/business/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop12.png"
                mode="apectFill"
              />
            </view>

            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">营业统计</view>
            </van-skeleton>
          </view>

          <view
            v-permission="['shop:chart:category']"
            class="contents-list-item"
            @click="goTo('/pages/cashier/statistics/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop04.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">销售统计</view>
            </van-skeleton>
          </view>
          <view
            v-permission="['shop:mulin:order:verify']"
            class="contents-list-item"
            @click="goTo('/pages/cancellation/add/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop27.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">订单核销</view>
            </van-skeleton>
          </view>
        </view>
      </view>

      <view
        class="contents"
        v-permission="[
          'shop:scTransfer:create',
          'shop:scTransfer:source',
          'shop:scTransfer:return:query',
          'shop:scTransfer:target',
          'shop:stock:query',
        ]"
      >
        <view class="contents-title">
          <van-skeleton title :loading="loading" title-width="60">
            <text>库存管理</text>
          </van-skeleton>
        </view>

        <view class="contents-list">
          <view
            v-permission="['shop:purchase:query']"
            class="contents-list-item"
            @click="goTo('/pages/logistics/notice/index')"
          >
            <view class="box">
              <up-badge
                bgColor="#F53F3F"
                max="99"
                :value="PurchaseLogisticsCount || 0"
              ></up-badge>
            </view>
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop17.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">物流通知</view>
            </van-skeleton>
          </view>
          <view
            v-permission="['shop:stock:query']"
            class="contents-list-item"
            @click="goTo('/pages/transfer/inventory/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop05.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">库存查询</view>
            </van-skeleton>
          </view>

          <view
            v-permission="[
              'shop:scTransfer:create',
              'shop:scTransfer:source',
              'shop:scTransfer:return:query',
              'shop:scTransfer:target',
            ]"
            class="contents-list-item"
            @click="goTo('/pages/transfer/home/index')"
          >
            <view class="box">
              <up-badge
                bgColor="#F53F3F"
                max="99"
                :value="(totallObj && totallObj.count) || 0"
              ></up-badge>
            </view>
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop07.png"
                mode="apectFill"
              />
            </view>

            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">调货</view>
            </van-skeleton>
          </view>
          <view
            v-permission="['shop:receive:query', 'shop:receive:create']"
            class="contents-list-item"
            @click="goTo('/pages/sends/home/index')"
          >
            <view class="box">
              <up-badge
                bgColor="#F53F3F"
                max="99"
                :value="purchaseCountObj || 0"
              ></up-badge>
            </view>

            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop18.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">收货单</view>
            </van-skeleton>
          </view>
          <view
            v-permission="[
              'shop:storePurchase:query',
              'shop:storePurchase:create',
            ]"
            class="contents-list-item"
            @click="goTo('/pages/self_store/home/index')"
          >
            <view class="box">
              <up-badge
                bgColor="#F53F3F"
                max="99"
                :value="(totallObj && totallObj.count) || 0"
              ></up-badge>
            </view>
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop26.png"
                mode="apectFill"
              />
            </view>

            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">自采入库</view>
            </van-skeleton>
          </view>
        </view>
      </view>
      <view
        class="contents"
        v-permission="[
          'shop:stock:query',
          'shop:stock:adjust:damage:create',
          'shop:stock:adjust:damage:query',
          'shop:product:query',
          'shop:plan:query',
          'shop:takeSheet:query',
        ]"
      >
        <view class="contents-title">
          <van-skeleton title :loading="loading" title-width="60">
            <text>商品管理</text>
          </van-skeleton>
        </view>
        <view class="contents-list">
          <view
            v-permission="['shop:product:query']"
            class="contents-list-item"
            @click="goTo('/pages/goods/goods_price/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shopthree.png"
                mode="apectFill"
              />
            </view>

            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">快速调价</view>
            </van-skeleton>
          </view>
          <view
            v-permission="[
              'shop:stock:query',
              'shop:stock:adjust:damage:create',
              'shop:stock:adjust:damage:query',
            ]"
            class="contents-list-item"
            @click="goTo('/pages/loss/home/index')"
          >
            <view class="box">
              <up-badge
                bgColor="#F53F3F"
                max="99"
                :value="UnApproveCount.count || 0"
              ></up-badge>
            </view>
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop21.png"
                mode="apectFill"
              />
            </view>

            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">报损</view>
            </van-skeleton>
          </view>
          <view
            v-permission="['shop:plan:query', 'shop:takeSheet:query']"
            class="contents-list-item"
            @click="goTo('/pages/stocktaking/home/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop19.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">库存盘点</view>
            </van-skeleton>
          </view>

          <view
            v-permission="[
              'shop:stock:unpack:query',
              'shop:stock:unpack:create',
            ]"
            class="contents-list-item"
            @click="goTo('/pages/unpacking/home/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop24.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">商品拆包</view>
            </van-skeleton>
          </view>

          <view
            v-permission="[
              'shop:requisition:plan:query',
              'shop:requisition:plan:create',
            ]"
            class="contents-list-item"
            @click="goTo('/pages/require_goods/home/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop25.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">要货</view>
            </van-skeleton>
          </view>
        </view>
      </view>
    </view>

    <!-- 管理端 -->

    <!-- <view v-permission="['shop:chart:product']"> 23424444444444</view> -->

    <view v-if="showSelect == 'admin'">
      <view
        class="contents"
        v-permission="[
          'manager:product:query',
          'manager:supplier:product:query',
        ]"
      >
        <view class="contents-title">
          <van-skeleton title :loading="loading" title-width="60">
            <text>商品管理</text>
          </van-skeleton>
        </view>

        <view class="contents-list">
          <view
            v-permission="['manager:product:query']"
            class="contents-list-item"
            @click="goTo('/pages/goods/goods_list/index?type=10')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop16.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">商品管理</view>
            </van-skeleton>
          </view>

          <!-- <view
            v-permission="['manager:product:query']"
            class="contents-list-item"
            @click="goTo('/pages/goods/goods_list/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shoptwo.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">编辑商品</view>
            </van-skeleton>
          </view> -->
          <view
            v-permission="['manager:product:query']"
            class="contents-list-item"
            @click="goTo('/pages/goods/goods_price/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shopthree.png"
                mode="apectFill"
              />
            </view>

            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">快速调价</view>
            </van-skeleton>
          </view>
          <view
            v-permission="['manager:stock:adjust:damage:query']"
            class="contents-list-item"
            @click="goTo('/pages/loss/list/index')"
          >
            <view class="box">
              <up-badge
                bgColor="#F53F3F"
                max="99"
                :value="UnApproveCount.count || 0"
              ></up-badge>
            </view>
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop21.png"
                mode="apectFill"
              />
            </view>

            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">报损</view>
            </van-skeleton>
          </view>
          <view
            v-permission="['manager:supplier:product:query']"
            class="contents-list-item"
            @click="goTo('/pages/supplier/goods_list/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop22.png"
                mode="apectFill"
              />
            </view>

            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">供应商商品</view>
            </van-skeleton>
          </view>
        </view>
      </view>

      <view class="contents">
        <view class="contents-title">
          <van-skeleton title :loading="loading" title-width="60">
            <text>仓库管理</text>
          </van-skeleton>
        </view>

        <view class="contents-list">
          <view
            v-permission="['manager:purchase:query']"
            class="contents-list-item"
            @click="goTo('/pages/logistics/notice/index')"
          >
            <view class="box">
              <up-badge
                bgColor="#F53F3F"
                max="99"
                :value="PurchaseLogisticsCount || 0"
              ></up-badge>
            </view>
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop17.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">物流通知</view>
            </van-skeleton>
          </view>

          <view
            v-permission="['manager:receive:query']"
            class="contents-list-item"
            @click="goTo('/pages/sends/list/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop18.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">货品签收单</view>
            </van-skeleton>
          </view>

          <view
            v-permission="['manager:stock:query']"
            class="contents-list-item"
            @click="goTo('/pages/manage/inventory/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop05.png"
                mode="apectFill"
              />
            </view>

            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">库存查询</view>
            </van-skeleton>
          </view>
          <view
            v-permission="[
              'manager:scTransfer:create',
              'manager:scTransfer:source',
              'manager:scTransfer:return:query',
              'manager:scTransfer:target',
            ]"
            class="contents-list-item"
            @click="goTo('/pages/transfer/home/index')"
          >
            <view class="box">
              <up-badge
                bgColor="#F53F3F"
                max="99"
                :value="totallObj.count || 0"
              ></up-badge>
            </view>
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop07.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">调货</view>
            </van-skeleton>
          </view>
          <view
            v-permission="['manager:plan:query', 'manager:takeSheet:query']"
            class="contents-list-item"
            @click="goTo('/pages/stocktaking/home/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop19.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">库存盘点</view>
            </van-skeleton>
          </view>
        </view>
      </view>

      <view class="contents">
        <view class="contents-title">
          <van-skeleton title :loading="loading" title-width="60">
            <text>销售管理</text>
          </van-skeleton>
        </view>

        <view class="contents-list">
          <view
            v-permission="['manager:order:query']"
            class="contents-list-item"
            @click="goTo('/pages/cashier/swich_shop/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop01.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">销售单查询</view>
            </van-skeleton>
          </view>

          <view
            v-permission="[
              'manager:chart:business',
              'manager:chart:shop',
              'manager:chart:category',
              'manager:chart:product',
              'manager:chart:payType',
            ]"
            class="contents-list-item"
            @click="goTo('/pages/count_to/index')"
          >
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop12.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">销售统计</view>
            </van-skeleton>
          </view>
          <!-- <view class="contents-list-item" @click="goTo('')">
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop12.png"
                mode="apectFill"
              />
            </view>

            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">营销管理</view>
            </van-skeleton>
          </view> -->

          <!-- <view class="contents-list-item" @click="goTo('')">
            <view class="contents-list-item-img">
              <up-skeleton
                avatarShape="square"
                avatar
                :title="false"
                rows="0"
                style="margin-left: 35rpx; width: 90rpx; height: 90rpx"
                v-if="loading"
              >
              </up-skeleton>
              <image
                v-if="!loading"
                src="@/static/home/shop23.png"
                mode="apectFill"
              />
            </view>
            <van-skeleton
              title
              :loading="loading"
              title-width="60"
              class="skeleton-com"
            >
              <view class="contents-title-text">用户分析</view>
            </van-skeleton>
          </view> -->
        </view>
      </view>
    </view>

    <view class="bt_food">
      <image src="@/static/index/zone.png" mode="scaleToFill" /><text
        >零壹聚提供技术支持</text
      >
    </view>
    <view class="noWork" v-if="showWord">
      <view class="noWork-k">
        <image src="@/static/index/noWork.png" mode="scaleToFill" />
        <view class="noWork-title">网络不太顺畅</view>
        <view class="noWork-des">请检查网络连接</view>
        <view class="noWork-btn"><text @click="reload">刷新</text> </view>
      </view>
    </view>
  </view>

  <!-- 版本更新模块 -->

  <up-popup
    :show="showVersion"
    :closeable="false"
    :round="10"
    bgColor="transparent"
    mode="center"
    @close="closeVersion"
    :closeOnClickOverlay="false"
  >
    <view class="version-p">
      <view class="top">
        <image src="@/static/home/up_bc_to.png" mode="widthFix" />
        <view class="top-title">
          <view class="name">发现新版本</view>
          <view class="v">V{{ Version.version }}</view>
        </view>
      </view>

      <view class="content">
        <view class="title">更新内容：</view>
        <view class="list">
          <text>{{ Version.remark }}</text>
        </view>
      </view>

      <view class="bt">
        <view class="qx" @click="VersionQx">暂不</view>
        <view class="qr" @click="VersionQr">立即更新</view>
      </view>
    </view>
  </up-popup>
</template>

<style lang="scss" scoped>
@import "index.scss";
</style>
